package cn.fzkj.helloworld01;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedAbstractActor;

/**
 * @ author mr
 * @ description
 * @ since 2024/12/2
 */
public class HelloActor extends UntypedAbstractActor {

    ActorRef greeterRef;
    @Override
    public void preStart() throws Exception { //是Akka的回调方法，在Actor启动前会被Akka调用，完成一些初始化操作
        greeterRef = getContext().actorOf(Props.create(Greeter.class), "greeter-actor");
        System.out.println("Greeter Actor Path :" + greeterRef.path());
        greeterRef.tell("hello greeter", getSelf());
    }

    @Override
    public void onReceive(Object message) throws Throwable {
        System.out.println("hello actor receive => " + message);

        getSender().tell("hello actor tell you", self());
    }
}
